import { Injectable } from '@nestjs/common';
import * as svgCaptcha from 'svg-captcha'
@Injectable()
export class UserService {
    getCode(req, res) {
        const captcha = svgCaptcha.create({
            size: 4,//生成几个验证码
            fontSize: 50, //文字大小
            width: 100,  //宽度
            height: 34,  //高度
            background: '#cc9966',  //背景颜色
        })
        req.session.code = captcha.text //存储验证码记录到session
        res.type('image/svg+xml')
        res.send(captcha.data)
    }

    createUser(req, body) {
        console.log(body, req.session.code, 'log')
        if (req.session.code.toLocaleLowerCase() === body.code.toLocaleLowerCase()) {
            return {
                code: '200',
                message: '添加成功'
            }
        } else {
            return {
                code: '200',
                message: '验证码错误'
            }
        }
    }
}
